/**
 * 
 */
package com.dianwoba.core.jackson;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * @author Zhu
 * @date 2016-1-20 下午2:35:35
 * @description
 */
public class ScaleSerialize extends JsonSerializer<Number> {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.fasterxml.jackson.databind.JsonSerializer#serialize(java.lang.Object,
	 * com.fasterxml.jackson.core.JsonGenerator,
	 * com.fasterxml.jackson.databind.SerializerProvider)
	 */
	@Override
	public void serialize(Number value, JsonGenerator gen,
			SerializerProvider serializers) throws IOException,
			JsonProcessingException {
		BigDecimal decimalValue = BigDecimal.valueOf(value.doubleValue());
		decimalValue = decimalValue.setScale(1, RoundingMode.FLOOR);
		gen.writeNumber(decimalValue);
	}
}
